﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CinemaSystem
{
    public partial class tianjia : Form
    {
       
        public tianjia()
        {

            InitializeComponent();
        }
        string sqlstr;
        private void tianjia_Load(object sender, EventArgs e)
        {
            sqlstr = string.Format("select * from Movie");
            dt = DBHelper.GetDataTable(sqlstr);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dt;


        }
        DataTable dt = new DataTable();
        private void button1_Click(object sender, EventArgs e)
        {
          
        }

        private void dataGridView1_Enter(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            

            textBox1.Text = dt.Rows[id]["Moviename"].ToString();
            textBox2.Text = dt.Rows[id]["type"].ToString();
            textBox3.Text = dt.Rows[id]["director"].ToString();
            textBox4.Text = dt.Rows[id]["Tostar"].ToString();

         
        }
        int id;
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            id = e.RowIndex;
        }

        private void bt1_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("update Movie set Moviename='{0}'where Movieid='{1}'", textBox1.Text, dt.Rows[id]["Movieid"].ToString());
            int i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {  
                sqlstr = string.Format("select * from Movie");
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = dt;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("update Movie set director='{0}'where Movieid='{1}'", textBox3.Text, dt.Rows[id]["Movieid"].ToString());
            int i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {
               

                sqlstr = string.Format("select * from Movie");
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = dt;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("update Movie set [type]='{0}'where Movieid='{1}'", textBox2.Text, dt.Rows[id]["Movieid"].ToString());
            int i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {
               

                sqlstr = string.Format("select * from Movie");
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = dt;
            }
        }
      
        private void button5_Click(object sender, EventArgs e)
        {
            sqlstr = string.Format("update Movie set  Tostar='{0}'where Movieid='{1}'", textBox4.Text, dt.Rows[id]["Movieid"].ToString());
            int i = DBHelper.ExecuteNonQuery(sqlstr);
            if (i > 0)
            {


                sqlstr = string.Format("select * from Movie");
                dt = DBHelper.GetDataTable(sqlstr);
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource = dt;
            }
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((MessageBox.Show("您是否确定要删除？", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                 == DialogResult.Yes))
            {

                
                string sqlstr = string.Format("delete from Movie where Movieid={0}", dt.Rows[id]["Movieid"].ToString());
                int i = DBHelper.ExecuteNonQuery(sqlstr);
                if (i > 0)
                {
                    MessageBox.Show("删除成功！");
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }
    }
}
